from django.db import models

# Create your models here.

# 商品类别表
class Category(models.Model):
    cate_name = models.CharField('类别名称',max_length=20)

    class Meta:
        db_table = 'category'
        verbose_name_plural = '商品没别表'

    def __str__(self):
        return self.cate_name

# 商品表

class Goods(models.Model):
    sku_name = models.CharField('商品名称',max_length=100)
    price = models.DecimalField('原价',max_digits=13,decimal_places=2)
    selling_price = models.DecimalField('售价',max_digits=13,decimal_places=2)
    img = models.CharField('默认图片',max_length=200)
    title = models.CharField('标题',max_length=30)
    # TextField : 长文本类型
    instruction = models.TextField('商品介绍',default='')
    count = models.IntegerField('销量',default=0)
    stock = models.IntegerField('库存',default=0)
    cate = models.ForeignKey(to=Category,on_delete=models.CASCADE,verbose_name='商品类别')
    online = models.BooleanField('是否在售',default=True)

    def __str__(self):
        return self.sku_name

    class Meta:
        db_table = 'goods'
        verbose_name_plural = '商品表'

# 商品图片表
class GoodImg(models.Model):
    img = models.CharField('图片地址',max_length=200)
    # null=True,blank=True:可以为空
    title = models.CharField('标题',max_length=20,null=True,blank=True)
    good = models.ForeignKey(Goods,on_delete=models.CASCADE,verbose_name='商品')

    def __str__(self):
        return '%s:%s'%(self.good.sku_name,self.img)

    class Meta:
        db_table = 'goodimg'
        verbose_name_plural = '商品图片表'


# 轮播图
class Carousel(models.Model):
    imgPath = models.CharField('轮播图',max_length=200)
    describes = models.CharField('图片描述',max_length=200)

    def __str__(self):
        return '轮播图%d'%self.id

    class Meta:
        db_table = 'carousel'
        verbose_name_plural = '轮播图'







